package sbc.group1.lab1.alt;

import java.awt.EventQueue;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import javax.swing.JFrame;

import org.mozartspaces.core.MzsCoreException;

public class FactoryGui {

    private JFrame frame;
    private CarService service;

    /**
     * Launch the application.
     */
    public static void main(final String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    FactoryGui window = new FactoryGui();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     * @throws InterruptedException 
     * @throws MzsCoreException 
     * @throws NotBoundException 
     * @throws RemoteException 
     * @throws MalformedURLException 
     */
    public FactoryGui() throws MzsCoreException, InterruptedException, MalformedURLException, RemoteException, NotBoundException {
        service = (CarService) Naming.lookup("rmi://localhost:1099/CarService");
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     * @throws InterruptedException 
     * @throws MzsCoreException 
     * @throws RemoteException 
     */
    private void initialize() throws MzsCoreException, InterruptedException, RemoteException {
        frame = new JFrame();
        frame.getContentPane().add(new FactoryPanel(service));
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}
